package dao;

import java.util.ArrayList;
import java.util.List;

import models.Department;
import play.modules.objectify.Datastore;
import play.modules.objectify.ObjectifyService;

import com.googlecode.objectify.helper.DAOBase;

public class DepartmentDao extends DAOBase {

	static {
		ObjectifyService.register(Department.class);
	}

	public List<Department> findAll() {
		Iterable<Department> deps = Datastore.query(Department.class).fetch();
		List<Department> allDepartments = new ArrayList<Department>();
		for (Department d : deps) {
			allDepartments.add(d);
		}
		return allDepartments;
	}

	public void save(Department department) {
		Datastore.put(department);
	}
	
	public static Department findById(Long id) {
		return Datastore.find(Department.class, id, true);
	}

	public static void delete(Long id) {
		Department department = findById(id);
		Datastore.delete(department);
	}

}
